package com.note7_12.question2;

public class Product {

	private String factoryaddr; // 工厂地址
	private boolean discount; // 是否折扣
	private int itemno; // 商品编号
	private String name; // 商品名称
	private double price; // 商品单价
	private double price_scount = 0;// 打折后单价
	private int stockcount; // 库存量
	private String unit; // 计价单位

	public Product(String factoryaddr, boolean discount, int itemno, String name, double price, int stockcount,
			String unit) {
		if (factoryaddr == null) {
			this.factoryaddr = "未知产地";
		} else {
			this.factoryaddr = factoryaddr;
		}

		this.discount = discount;
		this.itemno = itemno;
		this.name = name;
		if (discount == true) {
			this.price_scount = price * 0.7;
		}
		this.price = price;
		this.stockcount = stockcount;
		this.unit = unit;
	}

	// 获取商品编号
	public int getItemno() {
		return itemno;
	}

	public String getUnit() {
		return unit;
	}

	public String getName() {
		return name;
	}

	public int getStockcount() {
		return stockcount;
	}

	public boolean isDiscount() {
		return discount;
	}

	public double getPrice() {
		return price;
	}

	public String getFactoryaddr() {
		return factoryaddr;
	}

	public double getPrice_scount() {
		return price_scount;
	}

	public boolean getDiscount() {
		return discount;
	}

	@Override
	public String toString() {
		if (this.price_scount == 0) {
			return "工厂地址：" + factoryaddr + "\n 是否打折中：否\n商品编号：" + itemno + "\n商品名称：" + name + "\n单价=" + price + "\n 库存量："
					+ stockcount + "\n计价单位：" + unit + "\n";
		} else {
			return "工厂地址：" + factoryaddr + "\n是否打折中：是\n商品编号：" + itemno + "\n商品名称：" + name + "\n单价=" + price + "\n折后价格为："
					+ price_scount + "\n库存量：" + stockcount + "\n计价单位：" + unit + "\n";
		}

	}

}
